#!/usr/bin/perl -w # for syntax highlighting
package clreqd_modules;

use strict;
use lvm;

# This will return ERROR message or OK newsize
# The newsize might be larger than requested size for certain volume managers

sub lvm_lvresize {
my %ARGS=@_;

	my $vgname=$ARGS{VGNAME};
	my $lvname=$ARGS{LVNAME};

	my $kbsize=0;
	
	if(exists($ARGS{MBSIZE}) && exists($ARGS{MBSIZE})) {
		return "ERROR - Only specify one of MBSIZE or KBSIZE";
	}
	if(exists($ARGS{MBSIZE})) {
		$kbsize=1024*int($ARGS{MBSIZE});
	}
	if(exists($ARGS{KBSIZE})) {
		$kbsize=int($ARGS{KBSIZE});
	}
	if($kbsize==0) {
		return "ERROR - Must specify one of MBSIZE or KBSIZE";
	}

	# HERE
	my $LVM_STUFF=new lvm();
	if(!defined($LVM_STUFF)) {
		return "ERROR - Unable to determine LVM/VXVM environment!";
	}
	
	my ($status,$size,$open)=$LVM_STUFF->get_lvinfo(VGNAME=>$vgname,LVNAME=>$lvname);
	if(!defined($status)) {
		return "ERROR Volume '$lvname' does not exist in VG/DG '$vgname'.";
	}
	my $newsize;
	($status,$newsize)=$LVM_STUFF->lvresize(VGNAME=>$vgname,LVNAME=>$lvname,SIZE=>$kbsize);
	if($status==1) {
		if(exists($ARGS{MBSIZE})) {
			$newsize/=1024; # return value in MB
		}
		return "OK $newsize";
	}
	if(defined($newsize)) {
		return "ERROR RC=$status [$newsize] from lvresize";
	}
	return "ERROR RC=$status from lvresize";
}

1;
